package thread;
/**
 * 中断线程
 */
public class SleepDemo2 {
    public static void main(String[] args) {
        Thread wkj = new Thread("王克晶"){
            public void run(){
                try {
                    System.out.println(getName()+"累了睡一会儿");
                    Thread.sleep(10000000);
                } catch (InterruptedException e) {
                    System.out.println("谁呀！谁呀！谁呀！");
                }
                System.out.println(getName()+"醒了");
            }
        };

        Thread fcq = new Thread("范传奇"){
            public void run(){
                System.out.println(getName()+"中午去哪儿吃饭呢?");
                try {
                    Thread.sleep(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(getName()+"问问克晶吧!");
                wkj.interrupt(); //中断睡眠，触发wkj线程的InterruptedException异常
            }
        };

        wkj.start();
        fcq.start();
    }
}


















